package com.mouliu.base.design014;

/**
 * @author mouliu
 * @create 2018-04-07-下午9:33
 */
public class FutureData implements Data {
    private RealData realData;

    private boolean isReady = false;
    public synchronized void setRealData(RealData realData){
        //如果已经装载完毕了，就直接返回
        if (isReady){
            return;
        }
        //如果没有装载，进行装载真实对像
        this.realData = realData;
        isReady  = true;
        //进行通知
        this.notify();
    }
    @Override
    public String getRequest() {
        //如果没有状态好，程序就一直处于堵塞状态
        while (!isReady){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return this.realData.getRequest();

    }
}
